package cc.gu.tank.sprite;

import cc.gu.tank.sound.SoundEffect;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.image.Image;

/**
 * @Author: GuSongLiao
 * @Date: 2025/9/29 16:09
 * @Description: 爆炸类
 */
public class Boom extends Sprite {

    int step = 0;

    public static double WIDTH = 64, HEIGHT = 64;

    Image[] images = new Image[]{
            new Image("image/explode1.png"),
            new Image("image/explode2.png"),
            new Image("image/explode3.png"),
            new Image("image/explode4.png"),
            new Image("image/explode5.png"),
            new Image("image/explode6.png"),
            new Image("image/explode7.png"),
            new Image("image/explode8.png"),
            new Image("image/explode9.png"),
    };

    public Boom(Bullet bullet) {
        super(null, bullet.x, bullet.y, WIDTH, HEIGHT);
        SoundEffect.play("sound/explosion.wav");
    }

    @Override
    public void draw(GraphicsContext graphicsContext2D) {
        this.image = images[step++];
        double ex = x - image.getWidth()/2;
        double ey = y - image.getHeight()/2;
        graphicsContext2D.drawImage(image, ex, ey);
        if (step >= images.length) alive = false;
    }
}
